/*
 * @Author: your name
 * @Date: 2021-01-11 17:35:52
 * @LastEditTime: 2021-05-06 16:18:03
 */
import { getToken } from '@utils/auth'
// eslint-disable-next-line no-unused-vars
import { getUserInfo, auditeUserRealName } from '@api'

const state = {
  token: getToken().token,
  userId: getToken().userId,
  info: null
}
const mutations = {
  SET_USERINFO: (state, info) => {
    state.info = info
  }
}
const actions = {
  // 获取用户信息
  getInfo ({ commit, state }) {
    return new Promise((resolve, reject) => {
      getUserInfo().then(res => {
        const { content } = res
        commit('SET_USERINFO', content)
        resolve(content)
      }).catch(error => {
        reject(error)
      })
    })
  },
  // 实名认证
  auditeUserRealName ({ commit, state }) {
    const { id } = state.info
    auditeUserRealName({
      id,
      status: 'AUDITED'
    }).then(res => {
      console.log('auditeUserRealName', res)
    })
  }
}

export default {
  // namespaced: true,
  state,
  mutations,
  actions
}
